#include "stc15f2k60s2.h"
#include <intrins.h>
#include "lcd12864.h"

/***************
12864????
???????????
***************/

unsigned char code CharCode1[]="2020";
unsigned char code CharCode2[]="1010";

//??STC15W4K56S4??IO????
//io???? P0~7 ????IO?   




void IO_init(void)
{
  P0M0 = 0X00;	P0M1 = 0X00;
	P1M0 = 0X00;  P1M1 = 0X00;
	P2M0 = 0X00;	P2M1 = 0X00;
	P3M0 = 0X00;	P3M1 = 0X00;
	P4M0 = 0X00;	P4M1 = 0X00;  	
	P5M0 = 0X00;	P5M1 = 0X00;  	
	P6M0 = 0X00;	P6M1 = 0X00;  	
	P7M0 = 0X00;	P7M1 = 0X00;  
}

/*****
12864???????
???????????500ms????
********/
void display()
{
		uchar i,j,k;
		LCD12864_Init();
		for(k=5;k>=1;k--)
		{
				i=0;
				j=0;
				LCD12864_WriteCmd(0x01);         //??LCD12864?????
				if(k!=5)                         //?k???5,??lcd????0.1.2.3,k=5?,
				{                                //k-1=4,?????,???k=5???????????
					LCD12864_SetWindow(k-1, 0);  //?????????????????,k-1?3.2.1.0
					while(CharCode1[i]!='\0')    //??????????,????
					{
						LCD12864_WriteData(CharCode1[i]);  //?12864???
						i++;                               //???????,???++,?????
					}
				}
				if(k!=1)                        //k???1???????
				{
					LCD12864_SetWindow(k-2, 0);   //k-2???3.2.1.0,?????????
					while(CharCode2[j]!='\0')     //??????????,????
					{
						LCD12864_WriteData(CharCode2[j]);  //?12864???
						j++;                               //???????
					}
				}
				LCD12864_Delay1ms(5000);               //??500ms
		}

}

void main()
{
	IO_init();	 //??STC15W4K56S4 IO????
	//??STC????P20 P21 22?????
	P2M1 &= ~(1<<2),P2M0 |=  (1<<2); 
	P2M1 &= ~(1<<1),P2M0 |=  (1<<1); 
	P2M1 &= ~(1<<0),P2M0 |=  (1<<0); 	
  
	LCD12864_Init();
	while(1)
	{
		display();	
	}
}

